import { rpx } from "@/utils/rem";
export function getChartOption(vm, data, chart) {
    
    let option = {
        backgroundColor: 'rgba(255,255,255,0)',
        // legend: {
        //     icon: 'rect',
        //     textStyle: {
        //         fontFamily: 'Customer-Font',
        //         color: '#fff',
        //         fontSize: 18,
        //         padding: [5, 10]
        //     },
        //     itemWidth: 12,
        //     itemHeight: 12,
        //     itemGap: 20,
        //     left: '30%',
        //     bottom: 0,
        //     width: 600,
        //     data: [
        //         {
        //             name: '30-39嵗',
        //             itemStyle: {
        //                 color: '#ED5767'
        //             }
        //         },
        //         {
        //             name: '40-49嵗',
        //             itemStyle: {
        //                 color: '#95D6B6'
        //             }
        //         },
        //         {
        //             name: '50-59嵗',
        //             itemStyle: {
        //                 color: '#FF7723'
        //             }
        //         },
        //         {
        //             name: '≥60嵗',
        //             itemStyle: {
        //                 color: '#756CBD'
        //             }
        //         }
        //     ]
        // },
        grid: {
            right: '4%',
            top: '4%',
            left: '2%',
            bottom: '2%',
            containLabel: true,
        },
        xAxis: {
            type: 'category',
            boundaryGap: true,
            data: ['局級', '副局級', '廳級', '處級', '組級', '科級'],
            axisLabel: {
                //坐标轴刻度标签的相关设置。
                interval: 0, //设置为 1，表示『隔一个标签显示一个标签』
                //	margin:15,
                textStyle: {
                    fontFamily: 'Customer-Font',
                    color: '#96C3DD',
                    fontStyle: 'normal',
                    fontSize: rpx(16)
                }
            },
            axisTick: {
                //坐标轴刻度相关设置。
                show: false
            },
            axisLine: {
                //坐标轴轴线相关设置
                lineStyle: {
                    color: '#245481'
                }
            },
            splitLine: {
                //坐标轴在 grid 区域中的分隔线。
                show: false
            }
        },
        yAxis: [
            {
                name: '單位:人',
                nameTextStyle: {
                    color: '#96C3DD',
                    fontSize: 18,
                    padding: [-25, 30, 0, 15],
                    verticalAlign: 'top'
                },
                type: 'value',
                // splitNumber: 3,
                axisLabel: {
                    textStyle: {
                        margin: 50,
                        fontFamily: 'Customer-Font',
                        color: '#96C3DD',
                        fontStyle: 'normal',
                        fontSize: 18
                    }
                },
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: 'rgba(60, 154, 234, 0.2)'
                    }
                }
            }
        ],
        series: [
            {
                name: '30-39嵗',
                type: 'pictorialBar',
                barWidth: '28%',
                barCategoryGap: '12%',
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                        offset: [-52, 0],
                        formatter: (params) => {
                            return `${formatNumberRgx(params.data)}`;
                        },
                        textStyle: {
                            fontFamily: 'Customer-Font',
                            color: '#FFFFFF',
                            fontSize: 18
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [
                                {
                                    offset: 0,
                                    color: 'rgba(255,134,134,1)' // 0% 处的颜色
                                },
                                {
                                    offset: 0.85,
                                    color: 'rgba(255,69,136,0.3)'
                                }
                            ],
                            globalCoord: false // 缺省为 false
                        } //渐变颜色
                    }
                },
                symbolOffset: ['-100%', '0'],
                symbol: 'path://M24.6172 36.0586C19.0324 69.1107 5.87873 116.853 0 136.592C23.27 137.51 66.1357 136.592 67.9728 136.592C68.7077 136.592 54.3783 90.4568 45.1927 36.0586C36.0072 -18.3396 31.5982 -5.25648 24.6172 36.0586Z',
                data: [1, 2, 14, 78, 3, 0]
            },
            {
                name: '40-49嵗',
                type: 'pictorialBar',
                barWidth: '28%',
                barCategoryGap: '12%',
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                        offset: [-20, 0],
                        formatter: (params) => {
                            return `${formatNumberRgx(params.data)}`;
                        },
                        textStyle: {
                            fontFamily: 'Customer-Font',
                            color: '#FFFFFF',
                            fontSize: 18
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [
                                {
                                    offset: 0,
                                    color: 'rgba(79,207,144,1)' // 0% 处的颜色
                                },
                                {
                                    offset: 0.85,
                                    color: 'rgba(149,214,182,0.3)'
                                }
                            ],
                            globalCoord: false // 缺省为 false
                        } //渐变颜色
                    }
                },
                symbolOffset: ['-40%', '0'],
                symbol: 'path://M24.6172 36.0586C19.0324 69.1107 5.87873 116.853 0 136.592C23.27 137.51 66.1357 136.592 67.9728 136.592C68.7077 136.592 54.3783 90.4568 45.1927 36.0586C36.0072 -18.3396 31.5982 -5.25648 24.6172 36.0586Z',
                data: [10, 28, 71, 207, 17, 5]
            },
            {
                name: '50-59嵗',
                type: 'pictorialBar',
                barWidth: '28%',
                barCategoryGap: '12%',
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                        offset: [11, 0],
                        formatter: (params) => {
                            return `${formatNumberRgx(params.data)}`;
                        },
                        textStyle: {
                            fontFamily: 'Customer-Font',
                            color: '#FFFFFF',
                            fontSize: 18
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [
                                {
                                    offset: 0,
                                    color: 'rgba(255,166,112,1)' // 0% 处的颜色
                                },
                                {
                                    offset: 0.85,
                                    color: 'rgba(229,116,47,0.3)'
                                }
                            ],
                            globalCoord: false // 缺省为 false
                        } //渐变颜色
                    }
                },
                symbolOffset: ['20%', '0'],
                symbol: 'path://M24.6172 36.0586C19.0324 69.1107 5.87873 116.853 0 136.592C23.27 137.51 66.1357 136.592 67.9728 136.592C68.7077 136.592 54.3783 90.4568 45.1927 36.0586C36.0072 -18.3396 31.5982 -5.25648 24.6172 36.0586Z',
                data: [48, 41, 115, 160, 17, 4]
            },
            {
                name: '≥60嵗',
                type: 'pictorialBar',
                barWidth: '28%',
                barCategoryGap: '12%',
                label: {
                    normal: {
                        show: true,
                        position: 'top',
                        offset: [48, 0],
                        formatter: (params) => {
                            return `${formatNumberRgx(params.data)}`;
                        },
                        textStyle: {
                            fontFamily: 'Customer-Font',
                            color: '#FFFFFF',
                            fontSize: 18
                        }
                    }
                },
                itemStyle: {
                    normal: {
                        color: {
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [
                                {
                                    offset: 0,
                                    color: 'rgba(117,108,189,1)' // 0% 处的颜色
                                },
                                {
                                    offset: 0.85,
                                    color: 'rgba(117,108,189,0.3)'
                                }
                            ],
                            globalCoord: false // 缺省为 false
                        } //渐变颜色
                    }
                },
                symbolOffset: ['90%', '0'],
                symbol: 'path://M24.6172 36.0586C19.0324 69.1107 5.87873 116.853 0 136.592C23.27 137.51 66.1357 136.592 67.9728 136.592C68.7077 136.592 54.3783 90.4568 45.1927 36.0586C36.0072 -18.3396 31.5982 -5.25648 24.6172 36.0586Z',
                data: [12, 8, 19, 23, 1, 1]
            }
        ]
    };
    return option;
}

function formatNumberRgx(num) {
    num = num == null ? 0 : num;
    const parts = num.toString().split('.');
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    return parts.join('.');
};